package edu.sandau.b230151.b23015135.service;

import edu.sandau.b230151.b23015135.mapper.BookMapper;
import edu.sandau.b230151.b23015135.model.Book;
import edu.sandau.b230151.b23015135.repository.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BookService {

    @Autowired
    private BookMapper bookMapper;
    @Autowired
    private BookRepository bookRepository;


    public List<Book> findAll(Book book) {
        if (book.getAuthor() != null || book.getName() != null) {
            return bookMapper.findAll(book);
        } else {
            return bookMapper.findAll(book); //mybatis
        }

    }

    public void deleteById(String id) {
        bookMapper.deleteById(id);
    }

    public void save(Book s) {
        bookMapper.save(s);
    }

    public Book getReferenceById(String id) {
        return bookMapper.getReferenceById(id);
    }

    public void update(Book s) {
        bookMapper.update(s);
    }
}
